home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue66 / Construc / Refactor / Source / fEditVersion.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-13  |  12.6 KB  |  344 lines

  1. unit fEditVersion;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Buttons, ExtCtrls, uBuildingObject, uRCBuilder;
  8.  
  9. type
  10.   Tf_editversion = class(TForm)
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     Label3: TLabel;
  14.     Label4: TLabel;
  15.     Label6: TLabel;
  16.     Label13: TLabel;
  17.     Label5: TLabel;
  18.     Label7: TLabel;
  19.     Label8: TLabel;
  20.     Label9: TLabel;
  21.     Label11: TLabel;
  22.     Label12: TLabel;
  23.     Label14: TLabel;
  24.     Label15: TLabel;
  25.     Label16: TLabel;
  26.     Panel1: TPanel;
  27.     Label18: TLabel;
  28.     Label10: TLabel;
  29.     Label19: TLabel;
  30.     Label20: TLabel;
  31.     Label21: TLabel;
  32.     Label22: TLabel;
  33.     L_nameOfExe: TLabel;
  34.     BitBtn1: TBitBtn;
  35.     BitBtn2: TBitBtn;
  36.     L_nameOfBuildProject: TLabel;
  37.     Label23: TLabel;
  38.    E_Major : TEdit;
  39.    E_Minor : TEdit;
  40.    E_Release : TEdit;
  41.    E_Build : TEdit;
  42.    E_AppID : TEdit;
  43.    E_ProductMajor : TEdit;
  44.    E_ProductMinor : TEdit;
  45.    E_ProductRelease : Tedit;
  46.    E_ProductBuild : TEdit;
  47.    E_Company : TEdit;
  48.    E_Description : TEdit;
  49.    E_Comments : TEdit;
  50.    E_InternalName : TEdit;
  51.    E_OriginalFilename : TEdit;
  52.    E_CopyRight : TEdit;
  53.    E_ProductName : TEdit;
  54.    E_Trademark : TEdit;
  55.    E_IconFilename : TEdit;
  56.    E_SMajor : TEdit;
  57.    E_SMinor : TEdit;
  58.    E_SRelease : TEdit;
  59.    E_SBuild : TEdit;
  60.    E_SAppID : TEdit;
  61.    E_SProductMajor : TEdit;
  62.    E_SProductMinor : TEdit;
  63.    E_SProductRelease : Tedit;
  64.    E_SProductBuild : TEdit;
  65.    E_SCompany : TEdit;
  66.    E_SDescription : TEdit;
  67.    E_SComments : TEdit;
  68.    E_SInternalName : TEdit;
  69.    E_SOriginalFilename : TEdit;
  70.    E_SCopyRight : TEdit;
  71.    E_SProductName : TEdit;
  72.    E_STrademark : TEdit;
  73.    E_SIconFilename : TEdit;
  74.     b_iconFileName: TBitBtn;
  75.     b_SIconFileName: TBitBtn;
  76.     OpenDialog: TOpenDialog;
  77.     m_merge: TMemo;
  78.     procedure FormCreate(Sender: TObject);
  79.     procedure BitBtn2Click(Sender: TObject);
  80.     procedure b_iconFileNameClick(Sender: TObject);
  81.     procedure E_majorKeyPress(Sender: TObject; var Key: Char);
  82.     procedure E_majorChange(Sender: TObject);
  83.     procedure E_descriptionChange(Sender: TObject);
  84.   private
  85.     fProjectName: string;
  86.     fFileName: string;
  87.     fBuilder: TBuilderClass;
  88.     fRC : TResourceHandler;
  89.     procedure SetFileName(const Value: string);
  90.     procedure setProjectName(const Value: string);
  91.     { Private declarations }
  92.   public
  93.     constructor EditSavings(aBuilder : TBuilderClass; const aProjectName, aFileName : string);
  94.     Procedure RetrieveSettings;
  95.     Procedure SaveSettings;
  96.  
  97.     Property Builder : TBuilderClass read fBuilder write fBuilder;
  98.     Property ProjectName : string read fProjectName write setProjectName;
  99.     Property FileName : string read fFileName write SetFileName;
  100.  
  101.   end;
  102.  
  103. var
  104.   f_editversion: Tf_editversion;
  105.  
  106. implementation
  107. uses uSelectDir, fMainForm;
  108. {$R *.DFM}
  109.  
  110. { TF_EditVersion }
  111.  
  112. constructor Tf_editversion.EditSavings(aBuilder : TBuilderClass; const aProjectName,
  113.   aFileName: string);
  114. begin
  115.   inherited create(application);
  116.   fBuilder := aBuilder;
  117.   fRC := fBuilder.ResourceHandler;
  118.   fBuilder.ProjectName := aProjectName;
  119.   FileName := afileName;
  120. end;
  121.  
  122. procedure Tf_editversion.RetrieveSettings;
  123. begin
  124.   fBuilder.ResourceHandler.clearSettings;
  125.   FBuilder.ResourceHandler.GetSettings(SlashSep(fBuilder.projectdir,cProjectList), rsProject );
  126.   L_nameOfBuildProject.caption := f_mainForm.MakeEllipsisFilename(fBuilder.ProjectDir, L_nameOfBuildProject.Width, L_nameOfBuildProject.canvas);
  127.   with FBuilder.ResourceHandler do begin
  128.    E_Major.text := VersionInfo[reMajor];
  129.    E_Minor.text := VersionInfo[reMinor];
  130.    E_Release.text := VersionInfo[reRelease];
  131.    E_Build.text := VersionInfo[reBuild];
  132.    E_AppID.text := VersionInfo[reAppID];
  133.    E_ProductMajor.text := VersionInfo[reProductMajor];
  134.    E_ProductMinor.text := VersionInfo[reProductMinor];
  135.    E_ProductRelease.text := VersionInfo[reProductRelease];
  136.    E_ProductBuild.text := VersionInfo[reProductBuild];
  137.    E_Company.text := VersionInfo[reCompany];
  138.    E_Description.text := VersionInfo[reDescription];
  139.    E_Comments.text := VersionInfo[reComments];
  140.    E_InternalName.text := VersionInfo[reInternalName];
  141.    E_OriginalFilename.text := VersionInfo[reOriginalFilename];
  142.    E_CopyRight.text := VersionInfo[reLegalCopyRight];
  143.    E_ProductName.text := VersionInfo[reProductName];
  144.    E_Trademark.text := VersionInfo[reLegalTrademarks];
  145.    e_IconFilename.text := VersionInfo[reIconFilename];
  146.    end;
  147.   fBuilder.ResourceHandler.clearSettings;
  148.   FBuilder.ResourceHandler.GetSettings(ChangeFileExt(FileName, '.VER'), rsFile);
  149.   L_nameOfExe.caption := f_mainForm.MakeEllipsisFilename(FileName, L_nameOfExe.Width, L_nameOfExe.canvas);
  150.   with FBuilder.ResourceHandler do begin
  151.    E_SMajor.text := VersionInfo[reMajor];
  152.    E_SMinor.text := VersionInfo[reMinor];
  153.    E_SRelease.text := VersionInfo[reRelease];
  154.    E_SBuild.text := VersionInfo[reBuild];
  155.    E_SAppID.text := VersionInfo[reAppID];
  156.    E_SProductMajor.text := VersionInfo[reProductMajor];
  157.    E_SProductMinor.text := VersionInfo[reProductMinor];
  158.    E_SProductRelease.text := VersionInfo[reProductRelease];
  159.    E_SProductBuild.text := VersionInfo[reProductBuild];
  160.    E_SCompany.text := VersionInfo[reCompany];
  161.    E_SDescription.text := VersionInfo[reDescription];
  162.    E_SComments.text := VersionInfo[reComments];
  163.    E_SInternalName.text := VersionInfo[reInternalName];
  164.    E_SOriginalFilename.text := VersionInfo[reOriginalFilename];
  165.    E_SCopyRight.text := VersionInfo[reLegalCopyRight];
  166.    E_SProductName.text := VersionInfo[reProductName];
  167.    E_STrademark.text := VersionInfo[reLegalTrademarks];
  168.    E_SIconFilename.text := VersionInfo[reIconFilename];
  169.    end;
  170.  
  171.  
  172.  
  173. end;
  174.  
  175. procedure Tf_editversion.SaveSettings;
  176. begin
  177.   fBuilder.ResourceHandler.clearSettings;
  178.   with FBuilder.ResourceHandler do begin
  179.    VersionInfo[reMajor] := E_Major.text;
  180.    VersionInfo[reMinor] := E_Minor.text;
  181.    VersionInfo[reRelease] := E_Release.text;
  182.    VersionInfo[reBuild] := E_Build.text;
  183.    VersionInfo[reAppID] := E_AppID.text;
  184.    VersionInfo[reProductMajor] := E_ProductMajor.text;
  185.    VersionInfo[reProductMinor] := E_ProductMinor.text;
  186.    VersionInfo[reProductRelease] := E_ProductRelease.text;
  187.    VersionInfo[reProductBuild] := E_ProductBuild.text;
  188.    VersionInfo[reCompany] := E_Company.text;
  189.    VersionInfo[reDescription] := E_Description.text;
  190.    VersionInfo[reComments] := E_Comments.text;
  191.    VersionInfo[reInternalName] := E_InternalName.text;
  192.    VersionInfo[reOriginalFilename] := E_OriginalFilename.text;
  193.    VersionInfo[reLegalCopyRight] := E_CopyRight.text;
  194.    VersionInfo[reProductName] := E_ProductName.text;
  195.    VersionInfo[reLegalTrademarks] := E_Trademark.text;
  196.    VersionInfo[reIconFilename] := E_IconFilename.text;
  197.    SaveSettings(SlashSep(fBuilder.projectdir,cProjectList));
  198.    end;
  199.   fBuilder.ResourceHandler.clearSettings;
  200.   with FBuilder.ResourceHandler do begin
  201.    VersionInfo[reMajor] := E_SMajor.text;
  202.    VersionInfo[reMinor] := E_SMinor.text;
  203.    VersionInfo[reRelease] := E_SRelease.text;
  204.    VersionInfo[reBuild] := E_SBuild.text;
  205.    VersionInfo[reAppID] := E_SAppID.text;
  206.    VersionInfo[reProductMajor] := E_SProductMajor.text;
  207.    VersionInfo[reProductMinor] := E_SProductMinor.text;
  208.    VersionInfo[reProductRelease] := E_SProductRelease.text;
  209.    VersionInfo[reProductBuild] := E_SProductBuild.text;
  210.    VersionInfo[reCompany] := E_SCompany.text;
  211.    VersionInfo[reDescription] := E_SDescription.text;
  212.    VersionInfo[reComments] := E_SComments.text;
  213.    VersionInfo[reInternalName] := E_SInternalName.text;
  214.    VersionInfo[reOriginalFilename] := E_SOriginalFilename.text;
  215.    VersionInfo[reLegalCopyRight] := E_SCopyRight.text;
  216.    VersionInfo[reProductName] := E_SProductName.text;
  217.    VersionInfo[reLegalTrademarks] := E_STrademark.text;
  218.    VersionInfo[reIconFilename] := E_SIconFilename.text;
  219.    SaveSettings(ChangeFileExt(FileName, '.VER'));
  220.    end;
  221. end;
  222.  
  223. procedure Tf_editversion.SetFileName(const Value: string);
  224. begin
  225.   fFileName := Value;
  226. end;
  227.  
  228. procedure Tf_editversion.setProjectName(const Value: string);
  229. begin
  230.   fProjectName := Value;
  231. end;
  232.  
  233. procedure Tf_editversion.FormCreate(Sender: TObject);
  234. begin
  235.   RetrieveSettings;
  236. end;
  237.  
  238. procedure Tf_editversion.BitBtn2Click(Sender: TObject);
  239. begin
  240.   SaveSettings;
  241. end;
  242.  
  243. procedure Tf_editversion.b_iconFileNameClick(Sender: TObject);
  244. begin
  245.   with opendialog do begin
  246.     if execute
  247.       then case TbitBtn(sender).tag of
  248.         0 : E_IconFilename.text := filename;
  249.         1 : E_SIconFileName.text := filename;
  250.         end;
  251.     end;
  252. end;
  253.  
  254. procedure Tf_editversion.E_majorKeyPress(Sender: TObject; var Key: Char);
  255. begin
  256.   if not (key in ['0'..'9', #27, #8, #9, #13])
  257.     then key := #0;
  258. end;
  259.  
  260. procedure Tf_editversion.E_majorChange(Sender: TObject);
  261. begin
  262.   If trim(Tedit(sender).Text) = ''
  263.     then Tedit(sender).text := '0';
  264. end;
  265.  
  266. procedure Tf_editversion.E_descriptionChange(Sender: TObject);
  267. var tmpsl : tstringlist;
  268.     i : TResourceTypeEnum;
  269. begin
  270.    tmpsl := tstringlist.create;
  271.    with FBuilder.ResourceHandler do
  272.      for i := low(i) to high(i) do
  273.        tmpsl.add('');
  274.  
  275.    tmpsl[ord(reMajor)] := E_Major.text;
  276.    tmpsl[ord(reMinor)] := E_Minor.text;
  277.    tmpsl[ord(reRelease)] := E_Release.text;
  278.    tmpsl[ord(reBuild)] := E_Build.text;
  279.    tmpsl[ord(reAppID)] := E_AppID.text;
  280.    tmpsl[ord(reProductMajor)] := E_ProductMajor.text;
  281.    tmpsl[ord(reProductMinor)] := E_ProductMinor.text;
  282.    tmpsl[ord(reProductRelease)] := E_ProductRelease.text;
  283.    tmpsl[ord(reProductBuild)] := E_ProductBuild.text;
  284.    tmpsl[ord(reCompany)] := E_Company.text;
  285.    tmpsl[ord(reDescription)] := E_Description.text;
  286.    tmpsl[ord(reComments)] := E_Comments.text;
  287.    tmpsl[ord(reInternalName)] := E_InternalName.text;
  288.    tmpsl[ord(reOriginalFilename)] := E_OriginalFilename.text;
  289.    tmpsl[ord(reLegalCopyRight)] := E_CopyRight.text;
  290.    tmpsl[ord(reProductName)] := E_ProductName.text;
  291.    tmpsl[ord(reLegalTrademarks)] := E_Trademark.text;
  292.    tmpsl[ord(reIconFilename)] := E_IconFilename.text;
  293.  
  294.    if (tmpsl[ord(reMajor)] = '0') or (tmpsl[ord(reMajor)] = '')
  295.      then tmpsl[ord(reMajor)] := E_SMajor.text;
  296.    if (tmpsl[ord(reMinor)] = '0') or (tmpsl[ord(reMinor)] = '')
  297.      then tmpsl[ord(reMinor)] := E_SMinor.text;
  298.    if (tmpsl[ord(reRelease)] = '0') or (tmpsl[ord(reRelease)] = '')
  299.      then tmpsl[ord(reRelease)] := E_SRelease.text;
  300.    if (tmpsl[ord(reBuild)] = '0') or (tmpsl[ord(reBuild)] = '')
  301.      then tmpsl[ord(reBuild)] := E_SBuild.text;
  302.    if (tmpsl[ord(reProductMajor)] = '0') or (tmpsl[ord(reProductMajor)] = '')
  303.      then tmpsl[ord(reProductMajor)] := E_SProductMajor.text;
  304.    if (tmpsl[ord(reProductMinor)] = '0') or (tmpsl[ord(reProductMinor)] = '')
  305.      then tmpsl[ord(reProductMinor)] := E_SProductMinor.text;
  306.    if (tmpsl[ord(reProductRelease)] = '0') or (tmpsl[ord(reProductRelease)] = '')
  307.      then tmpsl[ord(reProductRelease)] := E_SProductRelease.text;
  308.    if (tmpsl[ord(reProductBuild)] = '0') or (tmpsl[ord(reProductBuild)] = '')
  309.      then tmpsl[ord(reProductBuild)] := E_SProductBuild.text;
  310.    if (tmpsl[ord(reAppId)] = '0') or (tmpsl[ord(reAppId)] = '')
  311.      then tmpsl[ord(reAppId)] := E_SAppId.text;
  312.    if tmpsl[ord(reDescription)] = ''
  313.      then tmpsl[ord(reDescription)] := E_SDescription.text;
  314.    if tmpsl[ord(reComments)] = ''
  315.      then tmpsl[ord(reComments)] := E_SComments.text;
  316.    if tmpsl[ord(reCompany)] = ''
  317.      then tmpsl[ord(reCompany)] := E_SCompany.text;
  318.    if tmpsl[ord(reInternalName)] = ''
  319.      then tmpsl[ord(reInternalName)] := E_SInternalName.text;
  320.    if tmpsl[ord(reOriginalFileName)] = ''
  321.      then tmpsl[ord(reOriginalFileName)] := E_SOriginalFileName.text;
  322.    if tmpsl[ord(reLegalCopyright)] = ''
  323.      then tmpsl[ord(reLegalCopyright)] := E_SCopyright.text;
  324.    if tmpsl[ord(reLegalTrademarks)] = ''
  325.      then tmpsl[ord(reLegalTrademarks)] := E_STrademark.text;
  326.    if tmpsl[ord(reProductName)] = ''
  327.      then tmpsl[ord(reProductName)] := E_SProductName.text;
  328.    if tmpsl[ord(reIconFilename)] = ''
  329.      then tmpsl[ord(reIconFilename)] := E_SIconFilename.text;
  330.    m_merge.lines.clear;
  331.    m_merge.lines.add('Produces the following version information for');
  332.    m_merge.lines.add(f_mainForm.MakeEllipsisFilename(filename, m_merge.width, self.Canvas));
  333.    m_merge.lines.add('');
  334.    m_merge.lines.add('File Version = '+tmpsl[ord(reMajor)]+'.'+tmpsl[ord(reMinor)]+'.'+
  335.                    tmpsl[ord(reRelease)]+'.'+tmpsl[ord(reBuild)]);
  336.    m_merge.lines.add('Product Version = '+tmpsl[ord(reProductMajor)]+'.'+tmpsl[ord(reProductMinor)]+'.'+
  337.                    tmpsl[ord(reProductRelease)]+'.'+tmpsl[ord(reProductBuild)]);
  338.    with FBuilder.ResourceHandler do
  339.      for i := reAppid to reIconFileName do
  340.        m_merge.lines.add(ResourceName[i]+' = '+tmpsl[ord(i)]);
  341. end;
  342.  
  343. end.
  344.